Eddie's Lessons
Beginners Programming
'** Eddie - an LB Code Editor
' version 2
'adds version info to titlebar
'adds filedialog to ask for liberty.exe location
'stores liberty.exe location in disk file
'reads disk file to get liberty.exe location
'checks disk file for length with LOF()
'uses DefaultDir$
'uses RUN command to run code in LB - use chr$(34)
'building in error trapping
[VariableSetup]
'#f will be the handle for opening files
'note that Version$ is a reserved variable name
EddieVersion$ = "2"
'path to Liberty.exe for running programs:
LibertyExe$ = ""
'name of ini file for this version of Eddie
IniFile$ = "eddie2.ini"
'variable to hold contents of texteditor
text$ = ""
'filename for writing a temp file to disk
tempfile$ = DefaultDir$ + "\tempfile.bas"
'filename for user saving file to disk
savefile$ = ""
[WindowSetup]
NOMAINWIN
WindowWidth = 692 : WindowHeight = 413
UpperLeftX = INT((DisplayWidth-WindowWidth)/2)
UpperLeftY = INT((DisplayHeight-WindowHeight)/2)
[ControlSetup]
'menus
Menu #1, "&File", "&New", [new], "&Open", [open], "&Save", [save],_
|,"&Print", [print], "E&xit", [quit]
'LB will place Edit menu where you specify in list of menus
'do not use ampersand & in Edit menu caption
Menu #1, "Edit"
Menu #1, "&Run","R&un", [run]
Menu #1, "&Help", "He&lp", [help], "&About", [about]
'buttons for a toolbar lookalike
button #1.new, "New",[new],UL, 0, 0, 45, 20
button #1.open, "Open",[open],UL, 45, 0, 45, 20
button #1.save, "Save",[save],UL, 90, 0, 45, 20
button #1.print, "Print",[print],UL, 135, 0, 45, 20
button #1.cut, "Cut",[cut],UL, 190, 0, 45, 20
button #1.copy, "Copy",[copy],UL, 235, 0, 45, 20
button #1.paste, "Paste",[paste],UL, 280, 0, 45, 20
button #1.run, "Run",[run],UL, 335, 0, 45, 20
button #1.help, "Help",[help],UL, 380, 0, 45, 20
'a texteditor
texteditor #1.te, 2, 22, 680, 335
Open "Eddie - an LB Code Editor " + EddieVersion$ for Window as #1
'trap the close event, if the user closes the
'window with the X button
#1 "trapclose [quit]"
'set the font for the window and controls
#1 "font ms_sans_serif 10"
'set a custom font for the texteditor
#1.te "!font courier_new 10"
'cause the texteditor to resize automatically
'when the user resizes the window
#1.te "!autoresize"
[loop]
Wait
[quit]
close #1 : END
[new]
#1.te "!CLS"
Wait
[open]
filedialog "Open","*.bas",openfile$
if openfile$="" then wait
open openfile$ for input as #f
'dump contents of file into texteditor
#1.te "!contents #f"
close #f
Wait
[save]
'if the word SAVE is in the caption, LB
'automatically creates a SAVE dialog
filedialog "Save As","*.bas",savefile$
if savefile$="" then wait
'make sure that user had given the file a *bas extension
if right$(lower$(savefile$),4)<>".bas" then
savefile$=savefile$+".bas"
end if
'get contents of texteditor into string variable
#1.te "!contents? text$"
if text$="" then
notice "No file to save."
wait
end if
'open file and write text to it
open savefile$ for output as #f
#f text$
close #f
Wait
[print]
'get contents of texteditor into string variable
#1.te "!contents? text$"
if text$="" then
notice "No text to print."
wait
end if
'send text to printer
lprint text$
'cause printing to happen now
dump
Wait
[help]
'place code here
Wait
[about]
'place code here
Wait
[cut]
#1.te "!cut"
wait
[copy]
#1.te "!copy"
wait
[paste]
#1.te "!paste"
wait
[run]
'go to routine to get liberty.exe path
'into variable LibertyExe$$
gosub [GetLibertyPath]
'if we can't find the path to Liberty BASIC
'we must abort the RUN operation
if LibertyExe$="" then wait
'get contents of texteditor into string variable
#1.te "!contents? text$"
'if there is no code, then abort the RUN operation
if text$="" then
notice "No code to run."
wait
end if
'open file and write text to it
open tempfile$ for output as #f
print #f, text$
close #f
'use RUN command to run Liberty BASIC
'with this file loaded
'put filename in quotation marks, so
'that spaces do not break up the filename
RUN LibertyExe$ + " " + chr$(34) + tempfile$ + chr$(34)
wait
[GetLibertyPath]
'file to store path info is IniFile$
'open for append to see if file exists
'attempting to open a nonexistent file for INPUT causes an error
open IniFile$ for append as #f
lenFile = LOF(#f)
close #f
'if the length = 0, the file doesn't exist
if lenFile=0 then
filedialog "Find Liberty.exe","*liberty*.exe",LibertyExe$
if LibertyExe$="" then
'the user cancelled the filedialog
notice "Liberty.exe not found."
else
'the user selected liberty.exe on his computer
'open the ini file and store the information
open IniFile$ for output as #f
print #f, LibertyExe$
close #f
end if
else
'if the length is greater than 0, the file exists
'open it for input and read the first line
'into the variable LibertyExe$
open IniFile$ for input as #f
line input #f, LibertyExe$
close #f
end if
RETURN
Eddie's Lessons
Beginners Programming